package com.yonglian.management.service.impl;

import com.yonglian.management.domain.ProjectBaseInfo;
import com.yonglian.management.repository.ProjectBaseInfoRepository;
import com.yonglian.management.service.ProjectBaseInfoService;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link com.yonglian.management.domain.ProjectBaseInfo}.
 */
@Service
@Transactional
public class ProjectBaseInfoServiceImpl implements ProjectBaseInfoService {

    private final Logger log = LoggerFactory.getLogger(ProjectBaseInfoServiceImpl.class);

    private final ProjectBaseInfoRepository projectBaseInfoRepository;

    public ProjectBaseInfoServiceImpl(ProjectBaseInfoRepository projectBaseInfoRepository) {
        this.projectBaseInfoRepository = projectBaseInfoRepository;
    }

    @Override
    public ProjectBaseInfo save(ProjectBaseInfo projectBaseInfo) {
        log.debug("Request to save ProjectBaseInfo : {}", projectBaseInfo);
        return projectBaseInfoRepository.save(projectBaseInfo);
    }

    @Override
    public ProjectBaseInfo update(ProjectBaseInfo projectBaseInfo) {
        log.debug("Request to update ProjectBaseInfo : {}", projectBaseInfo);
        return projectBaseInfoRepository.save(projectBaseInfo);
    }

    @Override
    public Optional<ProjectBaseInfo> partialUpdate(ProjectBaseInfo projectBaseInfo) {
        log.debug("Request to partially update ProjectBaseInfo : {}", projectBaseInfo);

        return projectBaseInfoRepository
            .findById(projectBaseInfo.getId())
            .map(existingProjectBaseInfo -> {
                if (projectBaseInfo.getProjectName() != null) {
                    existingProjectBaseInfo.setProjectName(projectBaseInfo.getProjectName());
                }
                if (projectBaseInfo.getProjectManager() != null) {
                    existingProjectBaseInfo.setProjectManager(projectBaseInfo.getProjectManager());
                }
                if (projectBaseInfo.getProjectLocation() != null) {
                    existingProjectBaseInfo.setProjectLocation(projectBaseInfo.getProjectLocation());
                }
                if (projectBaseInfo.getAmount() != null) {
                    existingProjectBaseInfo.setAmount(projectBaseInfo.getAmount());
                }

                return existingProjectBaseInfo;
            })
            .map(projectBaseInfoRepository::save);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<ProjectBaseInfo> findAll(Pageable pageable) {
        log.debug("Request to get all ProjectBaseInfos");
        return projectBaseInfoRepository.findAll(pageable);
    }

    @Override
    @Transactional(readOnly = true)
    public Optional<ProjectBaseInfo> findOne(Long id) {
        log.debug("Request to get ProjectBaseInfo : {}", id);
        return projectBaseInfoRepository.findById(id);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete ProjectBaseInfo : {}", id);
        projectBaseInfoRepository.deleteById(id);
    }
}
